package com.zlp.service.impl;

import com.alibaba.fastjson.JSON;
import com.zlp.entity.SupplierCardDetail;
import com.zlp.mapper.SupplierCardDetailMapper;
import com.zlp.service.SupplierCardDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * SupplierCardDetailService 服务实现类
 * </p>
 *
 * @author LiPing.Zou
 * @since 2021-03-09
 */
@Service
@RequiredArgsConstructor
@Slf4j(topic = "SupplierCardDetailServiceImpl")
public class SupplierCardDetailServiceImpl implements SupplierCardDetailService {

    private final SupplierCardDetailMapper supplierCardDetailMapper;


    @Transactional(rollbackFor = Exception.class)
    public int addSupplierCardDetails(List<SupplierCardDetail> records){
        log.info("addSupplierCardDetails req records={}",JSON.toJSONString(records));
        int result = supplierCardDetailMapper.batchInsert(records);
        log.info("addSupplierCardDetails resp result={}",result);
        return result;

    }

    /**
     * 批量查询
     *
     * @param supplierCardIds ids集合
     * @return int
     * @author ZouLiPing
     * @date 2022/11/24 18:16
     */
    @Override
    public List<SupplierCardDetail> getSupplierCardDetails(List<Integer> supplierCardIds) {

        if (CollectionUtils.isEmpty(supplierCardIds)) {
            throw new RuntimeException("supplierCardIds 为空");
        }

        log.info("supplierCardIds req supplierCardIds={}",JSON.toJSONString(supplierCardIds));
        List<SupplierCardDetail>  supplierCardDetailList =  supplierCardDetailMapper.getSupplierCardDetails(supplierCardIds);
        log.info("supplierCardIds req supplierCardDetailList={}",JSON.toJSONString(supplierCardDetailList));
        return supplierCardDetailList;
    }


}
